package itheima.d10_doudizhu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class doudizhu {
    public static void main(String[] args) {
        //制作一副扑克牌
        List<Cad> poker = new ArrayList<>();

        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] points = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        int size =0;
            for (String point : points){
            size++;
            for (String color : colors){
                Cad cad = new Cad(color, point,size);
                poker.add(cad);
            }
        }
        System.out.println( poker);

            //添加大小王
            poker.add(new Cad("大王", "",888));
            poker.add(new Cad("小王", "",666));




        //洗牌
        Collections.shuffle(poker);
        System.out.println( "洗完牌后"+poker);



        //发牌
        List<Cad> player1 = new ArrayList<>();
        List<Cad> player2 = new ArrayList<>();
        List<Cad> player3 = new ArrayList<>();
        List<Cad> diPai = new ArrayList<>();

        for (int i = 0; i < poker.size()-3; i++) {
            if(i%3==0){
                player1.add(poker.get(i));
            }else if(i%3==1){
                player2.add(poker.get(i));
            }else{
                player3.add(poker.get(i));
            }
        }
        diPai.addAll(poker.subList(poker.size()-3, poker.size()));



        //看牌
        System.out.println("玩家1的牌是："+player1);
        System.out.println("玩家2的牌是："+player2);
        System.out.println("玩家3的牌是："+player3);
        System.out.println("底牌是："+diPai);

        //理牌
        Collections.sort(player1,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(player2,(c1,c2)->c1.getSize()-c2.getSize());
        Collections.sort(player3,(c1,c2)->c1.getSize()-c2.getSize());


        System.out.println("===码牌===");
        System.out.println("玩家1的牌是："+player1);
        System.out.println("玩家2的牌是："+player2);
        System.out.println("玩家3的牌是："+player3);
        System.out.println("底牌是："+diPai);



        //抢地主
        player3.addAll(diPai);



        //地主那底牌+理牌
        Collections.sort(player3,(c1,c2)->c1.getSize()-c2.getSize());


        System.out.println("===最终手牌===");
        System.out.println("玩家1的牌是："+player1);
        System.out.println("玩家2的牌是："+player2);
        System.out.println("玩家3的牌是："+player3);


    }
}
